import { BrowserWindow, desktopCapturer } from 'electron'
import * as path from 'path'
import { is } from '@electron-toolkit/utils'

let win

export const create = () => {
  win = new BrowserWindow({
    width: 900,
    height: 670,
    show: false,
    autoHideMenuBar: true,
    webPreferences: {
      sandbox: false,
      nodeIntegration: true,
      contextIsolation: false,
      preload: path.join(__dirname, '../preload/index.js')
    }
  })
  win.on('ready-to-show', () => {
    win.show()
  })

  win.webContents.on('did-finish-load', () => {})

  if (is.dev && process.env['ELECTRON_RENDERER_URL']) {
    win.loadURL(`${process.env['ELECTRON_RENDERER_URL']}/pages/control/index.html`)
    win.webContents.openDevTools()
  } else {
    win.loadFile(path.join(__dirname, '../renderer/index.html'))
  }
}
